import React,{useState} from 'react'

const BoardItem = (props) => {
const [deling, setDeling] = useState(false);

    let del = ()=>{
        if(deling){
            return;
        }
        let data = new FormData();
        data.append('id',props.data.id)
        fetch('/api/index/delmsg',{
            method:'POST',
            body:data
        }).then((r)=>{
            if(r.ok){
                window.location.reload();
            }
        })
        setDeling(!deling);
        
    }
    return (
        <div className='board-item'>
            <div className='board-icon'>
                <img className='' width={50} height={50} style={{margin:8}} src={`/img/${props.data.icon}`}></img>
            </div>
            <div className='board-main' >
                <a href={`/people/${props.data.userid}`}>{props.data.name}</a>
                <p style={{marginTop:8}}>{props.data.content}</p>
                <div>
                    <span style={{fontSize:12,color:'#9B9B9B',width:120}}>{props.data.date}</span>
                    {(props.data.userto==props.userid||props.data.userid==props.userid)?<a style={{float:'right',fontSize:12,padding:'4px 8px',}} className='del-btn' onClick={del}>删除</a>:''}
                </div>
                
            </div>
        </div>
    )
}

export default BoardItem
